<template>
  <li :class="'my-list-item '+(this.myList.activeIndex==index?'active':'')">
    <div @click="handleClick">
      <slot></slot>
    </div>
  </li>
</template>

<script>
export default {
  name: "my-list-item",
  props: ["index"],
  inject: ["activeIndex", "setActiveIndex", "myList"],
  data: function() {
    return {
      clazz: {
        //li的class值
        "my-item-list": true,
        active: false
      }
    };
  },
  methods: {
    handleClick: function(event) {
      // this.setActiveIndex(this.index)//操作父级的activeIndex
      this.myList.activeIndex = this.index;
    }
  }
};
</script>

<style lang="scss" scoped>
.active {
  background: #00a1d6;
  color: white;
}
div {
  padding: 1px 8px;
}
</style>


